(1) Field of the Invention
This invention relates to a microprocessor and a register saving method, and more particularly to a microprocessor capable of executing a program including subroutine calls and a register saving method that is executed by the microprocessor.
(2) Description of the Related Art
General microprocessor has a large number of registers therein. The registers are used to temporarily store data read from external memories or computational processing results. In addition, various addresses to be used for accessing the external memories are stored. Since the registers operate faster, as compared with the external memories, the computational processing can be accelerated by making the best use of the registers. Especially, registers usable for various purposes by programs are called general purpose registers.
By the way, a program to be executed by a microprocessor may include subroutine calls as well as sequential instruction executions. A subroutine is executed independently of an instruction calling the subroutine in the program, and there are variables (automatic variables) which are used only in the subroutine. Therefore, when a subroutine is called, data stored in registers which may be used in execution of the subroutine should be saved. On returning from the subroutine, the saved data should be restored back to the original registers.
In general, the register saving/restoring is performed by a program in which data movement between a register and an external memory is explicitly defined. That is, on the register saving, the program moves data from the register to a stack frame of the external memory, and at the same time updates various addresses in the register accordingly. Then, on the register restoring, the program moves the data from the stack frame to the original register and changes the various addresses back to the original state in the register (for example, refer to Japanese Unexamined Patent Application Publication No. 03-191426 and Japanese Unexamined Patent Application Publication No. 59-135551).
However, the conventional register saving/restoring method has a drawback that a cost for the saving/restoring process increases in proportional to the number of registers that are used in execution of subroutines. That is to say, since a program needs to successively access slow-speed external memories, a time for the saving/restoring process is increased. In addition, since one instruction is required for moving data from one register, the scale of the program is also increased. Especially, this problem is a big issue recently because more general purpose registers are provided in a microprocessor and more general purpose registers are used for computational processing.